//
//  FPReviewViewController.m
//  ForestPack
//
//  Created by jimmy on 2018/7/4.
//  Copyright © 2018年 郑洲. All rights reserved.

///  进入审核的界面

#import "FPReviewViewController.h"
#import "UIView+Utils.h"

#import "BaseTabBarViewController.h"

#import "HomeViewController.h"


@interface FPReviewViewController ()



@end

@implementation FPReviewViewController



-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    [self.navigationController.navigationBar setBackgroundImage:[self createImageWithColor:RGB_COLOR(237, 34, 59)] forBarMetrics:UIBarMetricsDefault];
    
}

- (UIImage *)createImageWithColor:(UIColor *)color {
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return theImage;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [self setReviewUI];
    
}

-(void)interHomeVC
{
    
//    HomeViewController *homeVc = [[HomeViewController alloc] init];
//    homeVc.hidesBottomBarWhenPushed = NO;
//    [self.navigationController pushViewController:homeVc animated:true];
    
    [self getData];
    [self.navigationController dismissViewControllerAnimated:true completion:nil];
}

-(void)getData
{
    // 点击按钮 先定位  拿到定位信息之后 在进行下面操作
    
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    [dict setValue:self.phoneNum forKey:@"mobile"];
    [dict setValue:self.enterpriseNameStr forKey:@"realname"];
    [dict setValue:self.passwordNum forKey:@"password"];
    [dict setValue:self.enterpriseImageUrl forKey:@"营业执照"]; // 营业执照
    [dict setValue:@(self.finalRegType) forKey:@"customer_type"];
    [dict setValue:kNSUDefaultReadKey(@"longitude") forKey:@"longitude"];
    [dict setValue:kNSUDefaultReadKey(@"latitude") forKey:@"latitude"];
    
    NSString *url = [NSString stringWithFormat:@"%@app/app_company_register",REQUESTHEADER];//企业用户注册
    [HttpManager postHttpRequestByPost:url andParameter:dict success:^(id successResponse) {
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
        if ([status isEqualToString:@"1"]) {
            kNSUDefaultSaveVauleAndKey(successResponse[@"token"], @"token");
            kNSUDefaultSaveVauleAndKey(self.phoneNum, @"phone");
        
//            FPReviewViewController *reviewVC = [[FPReviewViewController alloc] init];
//            [self.navigationController pushViewController:reviewVC animated:true];
        }else{
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [HttpManager showFail];
    }];
}

-(void)setReviewUI
{
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.frame = CGRectMake(50, NAVIGATION_BAR_HEIGHT + 40, SCREEN_WIDTH - 100, 46);
    [titleLabel setText:@"恭喜您！您的资料已提交成功\n等待审核!"];
    titleLabel.numberOfLines = 0;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.font = [UIFont systemFontOfSize:18];
    [self.view addSubview:titleLabel];
    
    UIImageView *centerImageView = [[UIImageView alloc] init];
    centerImageView.frame = CGRectMake(80, titleLabel.bottom + 30, SCREEN_WIDTH - 160, SCREEN_WIDTH - 160);
    centerImageView.image = [UIImage imageNamed:@"提交成功"];
    [self.view addSubview:centerImageView];
    
    UIButton *enterHomeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    enterHomeBtn.frame = CGRectMake(40, SCREEN_HEIGHT - 228 - NAV_HEIGHT, SCREEN_WIDTH - 80, 44);
    enterHomeBtn.backgroundColor = RGB_COLOR(237, 34, 59);
    enterHomeBtn.layer.masksToBounds = true;
    enterHomeBtn.layer.cornerRadius = 22;
    [enterHomeBtn setTitle:@"进入首页" forState:UIControlStateNormal];
    enterHomeBtn.titleLabel.font = [UIFont systemFontOfSize:18];
    [enterHomeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

    [enterHomeBtn addTarget:self action:@selector(enter) forControlEvents:UIControlEventTouchUpInside];

//    [enterHomeBtn addTarget:self action:@selector(interHomeVC) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:enterHomeBtn];
}

- (void)enter {
    kKeyWindow.rootViewController = [[BaseTabBarViewController alloc] init];
}


@end
